package com.ssm.studen.controller;

import com.ssm.studen.model.Questionbankinfo;
import com.ssm.studen.service.QuestionbankinfoService;
import com.ssm.studen.tool.ResponseMessage;
import com.ssm.studen.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 题库信息表：
 *          对外提供数据服务接口
 */
@Api(tags = "questionbankinfo")
@RestController
public class QuestionbankinfoController {

    @Autowired
    private QuestionbankinfoService questionbankinfoService;

    /*****************题库信息表查询******************/
    @ApiOperation("题库信息表查询")
    @RequestMapping(value = "/selectQuestionbankinfo",method = RequestMethod.PUT)
    public ResponseMessage selectQuestionbankinfo(int qnum){
        Map<String,List> map = new HashMap<>();
        List<Questionbankinfo> listQ = questionbankinfoService.selectQuestionbankinfo(qnum);
        map.put("list",listQ);
        return Result.success("200",map);
    }


    /*****************题库信息表添加******************/
    @ApiOperation("题库信息表添加")
    @RequestMapping(value = "/insertQuestionbankinfo",method = RequestMethod.GET)
    public int insertQuestionbankinfo(Questionbankinfo questionbankinfo){
        int IsAdd = 0;
        //传入数据判断
        //1.实体对象不能为空
        if(questionbankinfo != null){
            //2.不能为空
            if(questionbankinfo.getEqtnum()!=0&&
                    questionbankinfo.getQtype()!=0&&
                    questionbankinfo.getQcontent()!=null&&
                    questionbankinfo.getQpoint()!=0&&
                    questionbankinfo.getQanswer()!=null&&
                    questionbankinfo.getQtid()!=null&&
                    questionbankinfo.getQstart()!=null&&
                    questionbankinfo.getQalter()!=null&&
                    questionbankinfo.getQbz()!=null&&
                    questionbankinfo.getQissuetime()!=null&&
                    questionbankinfo.getQisissue()!=null){
                //3.添加数据
                IsAdd = questionbankinfoService.insertQuestionbankinfo(questionbankinfo);
            }
        }
        return IsAdd;
    }


    /*****************题库信息表修改更新******************/
    @ApiOperation("题库信息表修改更新")
    @RequestMapping(value = "/updateQuestionbankinfo",method = RequestMethod.GET)
    public ResponseMessage updateQuestionbankinfo(Questionbankinfo questionbankinfo){
        //传入的参数不能为空
        if(questionbankinfo != null){
            //参数当中主键不能为0
            if(questionbankinfo.getQnum() != 0){
                if(questionbankinfoService.updateQuestionbankinfo(questionbankinfo) == 1){
                    if(questionbankinfo.getEqtnum()!=0&&
                            questionbankinfo.getQtype()!=0&&
                            questionbankinfo.getQcontent()!=null&&
                            questionbankinfo.getQpoint()!=0&&
                            questionbankinfo.getQanswer()!=null&&
                            questionbankinfo.getQtid()!=null&&
                            questionbankinfo.getQstart()!=null&&
                            questionbankinfo.getQalter()!=null&&
                            questionbankinfo.getQbz()!=null&&
                            questionbankinfo.getQissuetime()!=null&&
                            questionbankinfo.getQisissue()!=null){
                        questionbankinfoService.updateQuestionbankinfo(questionbankinfo);
                    }
                    return Result.success("更新成功");
                }else{
                    return Result.error("更新失败");
                }
            }
        }
        return Result.error("传入参数不正确");
    }


    /*****************题库信息表删除******************/
    @ApiOperation("题库信息表删除")
    @RequestMapping(value = "/deleteQuestionbankinfo",method = RequestMethod.GET)
    public ResponseMessage deleteQuestionbankinfo(int qnum){
        if(qnum != 0){
            int del = 0;
            del = questionbankinfoService.deleteQuestionbankinfo(qnum);
            if(del>0){
                return Result.success("删除成功");
            }else{
                return Result.error("删除失败");
            }
        }else{
            return Result.error("删除的主键不能为“0”，请重新输入！");
        }
    }
}



























